(local (has-vc vectorcode-config) (pcall require :vectorcode.config))
(var vectorcode-cacher nil)
(when has-vc (set vectorcode-cacher (vectorcode-config.get_cacher_backend)))
(local RAG_Context-Window-Size 8000)
(local qwen-coder {:chat_input {:repo_context (fn [_ _ _]
                                                (var prompt-message "")
                                                (when has-vc
                                                  (local cache-result
                                                         (vectorcode-cacher.query_from_cache 0))
                                                  (each [_ file (ipairs cache-result)]
                                                    (set prompt-message
                                                         (.. prompt-message
                                                             :<file_separator>
                                                             file.path "\n"
                                                             file.document))))
                                                (set prompt-message
                                                     (vim.fn.strcharpart prompt-message
                                                                         0
                                                                         RAG_Context-Window-Size))
                                                (when (not= prompt-message "")
                                                  (set prompt-message
                                                       (.. "<repo_context>\n"
                                                           prompt-message
                                                           "\n</repo_context>")))
                                                prompt-message)
                                :template "{{{repo_context}}}
                    {{{language}}}
                    {{{tab}}}
                    <contextBeforeCursor>
                    {{{context_before_cursor}}}<cursorPosition>
                    <contextAfterCursor>
                    {{{context_after_cursor}}}"}
                   :system {:repo_context "9. Additional context from other files in the repository will be enclosed in <repo_context> tags. Each file will be separated by <file_separator> tags, containing its relative path and content."
                            :template "{{{prompt}}}
                    {{{guidelines}}}
                    {{{n_completion_template}}}
                    {{{repo_context}}}"}
                   :api_key :SILLICON_API_KEY
                   :end_point "https://api.siliconflow.cn/v1/completions"
                   :model :Qwen/Qwen2.5-Coder-7B-Instruct
                   :name :qwen-sillicon
                   :stream true
                   :optional {:max_tokens 256 :top_p 0.9}})

(local M {: qwen-coder})
M
